<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" rel="stylesheet" href="menu/meun.css">
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }

        body {
            background: #000 url(./assets/兴达八厂/背景兴达.jpg) no-repeat left top;
            background-size: 100%;
        }
    </style>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-form.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src="../conf/confURL.js"></script>
    <script src='../conf/dateTime.js'></script>
    <script>
        var code;//定义厂区编码全局变量
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do";
        // 基底部门权限
        var deptUrl = domain + getDeptRequest;
        // 八厂 厂区编码
        let deptCodeEight = "XD1112";
        // 九厂 厂区编码
        let deptCodeNine = "XD1113";
        // 总部 编码
        let deptCodeHead = "headQuarters";
        let defaultDeptCode = "";
        dataModel = new ht.DataModel();
        graphView = new ht.graph.GraphView(dataModel);
        let echartsArr = [];
        let warn = [];
        let H = [];
        let factory5B;
        //let factory2A;
        let factory5A;
        let factory2;
        let factory1;
        let factory8;
        let factory9;
        let factory3;
        //let generalFactory;
        //let electricFactory;
        let RK;
        let RK1;
        let FH;
        let FH1;
        let input1;
        let input2;
        let input5;
        let input6;
        let input3;
        let input4;
        let input7;
        let input8;
        var all_1;
        var all_2;
        function init() {
            //获取图纸
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/生产监控/product_base.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag();
                // 基地权限 获取有权限的部门编码
                getDeptCodeData();
                // 默认展示的报表数据
                get(defaultDeptCode);
                getData7();
                getData8();
                var a = getData6().HT_SC_ZZ_TREE;
                cd = menu(a);
            });
            //时间更新
            setInterval(function () {
                const dateTime = dataModel.getDataByTag("datetime");
                let time = updateTime();
                dateTime.a('time', time);
            }, 1000);
            //更新数据
            setInterval(function a() { getData(); getData1(); getData2() }, 1000 * 60 * 30);
            setInterval(function b() { getData3(); getData4(); getData5() }, 1000 * 60 * 5);

            // 基地权限
            function getDeptCodeData() {
                $.ajax({
                    url: deptUrl,
                    type: "POST",
                    headers: request_headers,
                    data: {},
                    async: false,
                    contentType: 'application/x-www-form-urlencoded',
                    success: function (res) {
                        res = JSON.parse(res);
                        if ('OK' === res._MSG_ && Boolean(res.deptCode)) {
                            defaultDeptCode = res.deptCode;
                        }
                    },
                    error: function (error) {
                    }
                });
                return defaultDeptCode;
            }

            //报表数据
            function get(code) {
                getData(code);
                    getData1(code);
                    getData2(code);
                    getData3(code);
                    getData4(code);
                    getData5(code);
            }
            graphView.addInteractorListener(function (e) {
                if (e.kind === 'clickData') {
                    //if (e.data._tag == 'generalFactory') {
                    //     get("HT_SC_ZZ_TREE_XDJSXD_XDZB")
                    // }
                    //if (e.data._tag == 'electricFactory') {                           
                    //     get("HT_SC_ZZ_TREE_XD1204")
                    // }
                    // if (e.data._tag == 'factory1') {                           
                    //     get(HT_SC_ZZ_TREE_XDJSXD_XD1107)
                    // }
                    // else if (e.data._tag == 'factory2') {
                    //     get("HT_SC_ZZ_TREE_XDJSXD_XD1108")
                    // }
                    // else if (e.data._tag == 'factory2A') {
                    //     get(code)
                    // }
                    // else if (e.data._tag == 'factory3') {
                    //     get("HT_SC_ZZ_TREE_XDJSXD_XD1109")
                    // }
                    // else if (e.data._tag == 'factory5A') {
                    //     get(code)
                    // }
                    // else if (e.data._tag == 'factory5B') {
                    //     get(code)
                    // }
                    // else 
                    if (e.data._tag === 'factory8') {
                        get(deptCodeEight);
                    } else if (e.data._tag === 'factory9') {
                        get(deptCodeNine);
                    }else if("base_1" === e.data._tag || "base_21" === e.data._tag){  // 总部
                        get(deptCodeHead);
                    }
                }
            });
        }
        //获取界面所有echarts标签厂区标签
        function tag() {
            all_1 = dataModel.getDataByTag('all_1');
            all_2 = dataModel.getDataByTag('all_2');
            factory5B = dataModel.getDataByTag("factory5B");
            //factory2A = dataModel.getDataByTag("factory2A")
            factory5A = dataModel.getDataByTag("factory5A");
            factory2 = dataModel.getDataByTag("factory2");
            factory1 = dataModel.getDataByTag("factory1");
            factory8 = dataModel.getDataByTag("factory8");
            factory9 = dataModel.getDataByTag("factory9");
            factory3 = dataModel.getDataByTag("factory3");
            RK = dataModel.getDataByTag("RK");
            RK1 = dataModel.getDataByTag("RK1");
            FH = dataModel.getDataByTag("FH");
            FH1 = dataModel.getDataByTag("FH1");
            input1 = dataModel.getDataByTag("input1");
            input2 = dataModel.getDataByTag("input2");
            input5 = dataModel.getDataByTag("input5");
            input6 = dataModel.getDataByTag("input6");
            input3 = dataModel.getDataByTag("input3");
            input4 = dataModel.getDataByTag("input4");
            input7 = dataModel.getDataByTag("input7");
            input8 = dataModel.getDataByTag("input8");
            //generalFactory = dataModel.getDataByTag("generalFactory")
            //electricFactory = dataModel.getDataByTag("electricFactory")
            for (let i = 1; i < 13; i++) { //循环获取echart标签
                echartsArr.push(dataModel.getDataByTag("echart" + i));
            }
            //获取警告框  
            for (let i = 1; i < 13; i++) {
                warn.push(dataModel.getDataByTag("warn" + i));
            }
            //获取表格框名字 
            for (let i = 1; i < 13; i++) {
                H.push(dataModel.getDataByTag("H" + i));
            }
        }
        //水能耗接口
        function err() {
            warn[0].s("2d.visible", true);
            warn[6].s("2d.visible", true);
            echartsArr[0].s("2d.visible", false);
            echartsArr[6].s("2d.visible", false);
        }
        function getData(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_SNHTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[0].s("2d.visible", false);
                        warn[6].s("2d.visible", false);
                        echartsArr[0].s("2d.visible", true);
                        echartsArr[6].s("2d.visible", true);
                        H[0].a("title", repData.HT_SC_JD_REPORT_SNHTJ.title);
                        H[6].s("text", repData.HT_SC_JD_REPORT_SNHTJ.title);
                        if(Boolean(repData.HT_SC_JD_REPORT_SNHTJ.data)) {
                            echartsArr[0].a("xAxis", repData.HT_SC_JD_REPORT_SNHTJ.data.month);
                            echartsArr[0].a("yAxis1", repData.HT_SC_JD_REPORT_SNHTJ.data.steam);
                            echartsArr[0].a("yAxis2", repData.HT_SC_JD_REPORT_SNHTJ.data.industry);
                            // echartsArr[0].a("yAxis3", repData.HT_SC_JD_REPORT_SNHTJ.data.circle);
                            echartsArr[6].a("xAxis", repData.HT_SC_JD_REPORT_SNHTJ.data.month);
                            echartsArr[6].a("yAxis1", repData.HT_SC_JD_REPORT_SNHTJ.data.steam);
                            echartsArr[6].a("yAxis2", repData.HT_SC_JD_REPORT_SNHTJ.data.industry);
                            // echartsArr[6].a("yAxis3", repData.HT_SC_JD_REPORT_SNHTJ.data.circle);
                        }
                    } else {
                        err()
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err()
                }
            });
        }
        //用电量统计接口
        function err1() {
            warn[1].s("2d.visible", true);
            warn[7].s("2d.visible", true);
            echartsArr[1].s("2d.visible", false);
            echartsArr[7].s("2d.visible", false);
        }
        function getData1(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_YDLTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[1].s("2d.visible", false);
                        warn[7].s("2d.visible", false);
                        echartsArr[1].s("2d.visible", true);
                        echartsArr[7].s("2d.visible", true);
                        H[1].a("title", repData.HT_SC_JD_REPORT_YDLTJ.title);
                        H[7].s("text", repData.HT_SC_JD_REPORT_YDLTJ.title);
                        if(Boolean(repData.HT_SC_JD_REPORT_YDLTJ.data)) {
                            echartsArr[1].a("xAxis", repData.HT_SC_JD_REPORT_YDLTJ.data.month);
                            echartsArr[1].a("yAxis2", repData.HT_SC_JD_REPORT_YDLTJ.data.electric);
                            echartsArr[7].a("xAxis", repData.HT_SC_JD_REPORT_YDLTJ.data.month);
                            echartsArr[7].a("yAxis2", repData.HT_SC_JD_REPORT_YDLTJ.data.electric);
                        }
                    } else {
                        err1()
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err1()
                }
            });
        }
        //天然气统计接口
        function err2() {
            warn[2].s("2d.visible", true);
            warn[8].s("2d.visible", true);
            echartsArr[2].s("2d.visible", false);
            echartsArr[8].s("2d.visible", false);
        }
        function getData2(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_TRQTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[2].s("2d.visible", false);
                        warn[8].s("2d.visible", false);
                        echartsArr[2].s("2d.visible", true);
                        echartsArr[8].s("2d.visible", true);
                        H[2].a("title", repData.HT_SC_JD_REPORT_TRQTJ.title);
                        H[8].s("text", repData.HT_SC_JD_REPORT_TRQTJ.title);
                        if(Boolean(repData.HT_SC_JD_REPORT_TRQTJ.data)) {
                            echartsArr[2].a("xAxis", repData.HT_SC_JD_REPORT_TRQTJ.data.month);
                            echartsArr[2].a("yAxis", repData.HT_SC_JD_REPORT_TRQTJ.data.gas);
                            echartsArr[8].a("xAxis", repData.HT_SC_JD_REPORT_TRQTJ.data.month);
                            echartsArr[8].a("yAxis", repData.HT_SC_JD_REPORT_TRQTJ.data.gas);
                        }
                    } else {
                        err2()
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err2()
                }
            });
        }
        //八厂成品入库统计接口
        function err3() {
            warn[3].s("2d.visible", true);
            warn[9].s("2d.visible", true);
            RK.s("2d.visible", false);
            RK1.s("2d.visible", false);
        }
        function getData3(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_CPRUKTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[3].s("2d.visible", false);
                        warn[9].s("2d.visible", false);
                        RK.s("2d.visible", true);
                        RK1.s("2d.visible", true);
                        H[3].a("title", repData.HT_SC_JD_REPORT_CPRUKTJ.title);
                        H[9].s("text", repData.HT_SC_JD_REPORT_CPRUKTJ.title);
                        echartsArr[3].a("dataArr", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].completionRate);
                        input1.a("ht.value", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].scheduledReceipt);
                        input2.a("ht.value", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].plannedProduction);
                        echartsArr[9].a("dataArr", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].completionRate);
                        input5.a("ht.value", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].scheduledReceipt);
                        input6.a("ht.value", repData.HT_SC_JD_REPORT_CPRUKTJ.data[0].plannedProduction);
                    } else {
                        err3()
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err3();
                }
            });
        }
        //八厂成品发货统计接口
        function err4() {
            warn[4].s("2d.visible", true);
            warn[10].s("2d.visible", true);
            FH.s("2d.visible", false);
            FH1.s("2d.visible", false);
        }
        function getData4(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_CPFHTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[4].s("2d.visible", false);
                        warn[10].s("2d.visible", false);
                        FH.s("2d.visible", true);
                        FH1.s("2d.visible", true);
                        H[4].a("title", repData.HT_SC_JD_REPORT_CPFHTJ.title);
                        H[10].s("text", repData.HT_SC_JD_REPORT_CPFHTJ.title);
                        echartsArr[4].a("dataArr", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].completionRate);
                        input3.a("ht.value", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].deliverAmount);
                        input4.a("ht.value", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].plannedProduction);
                        echartsArr[10].a("dataArr", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].completionRate);
                        input7.a("ht.value", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].deliverAmount);
                        input8.a("ht.value", repData.HT_SC_JD_REPORT_CPFHTJ.data[0].plannedProduction);
                    } else {
                        err4();
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err4();
                }
            });
        }
        //八厂吨平能耗接口
        function err5() {
            warn[5].s("2d.visible", true);
            warn[11].s("2d.visible", true);
            echartsArr[5].s("2d.visible", false);
            echartsArr[11].s("2d.visible", false);
        }
        function getData5(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_REPORT_DPNHTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        warn[5].s("2d.visible", false);
                        warn[11].s("2d.visible", false);
                        echartsArr[5].s("2d.visible", true);
                        echartsArr[11].s("2d.visible", true);
                        H[5].a("title", repData.HT_SC_JD_REPORT_DPNHTJ.title);
                        H[11].s("text", repData.HT_SC_JD_REPORT_DPNHTJ.title);
                        if(Boolean(repData.HT_SC_JD_REPORT_DPNHTJ.data)) {
                            echartsArr[5].a("xAxis", repData.HT_SC_JD_REPORT_DPNHTJ.data.month);
                            echartsArr[5].a("yAxis1", repData.HT_SC_JD_REPORT_DPNHTJ.data.dpnh);
                            echartsArr[11].a("xAxis", repData.HT_SC_JD_REPORT_DPNHTJ.data.month);
                            echartsArr[11].a("yAxis1", repData.HT_SC_JD_REPORT_DPNHTJ.data.dpnh);
                        }
                    } else {
                        err5()
                    }
                },
                error: function (error) {
                    //console.log('err');
                    err5()
                }
            });
        }
        //菜单接口
        function getData6() {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_ZZ_TREE"
                },
                headers: request_headers,
                async: false,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res, handleJson);
                    if (repData._MSG_ === 'OK' && repData.visible === true) {
                        document.getElementById("node").style.display = "block"
                    } else {
                        document.getElementById("node").style.display = "none"
                    }
                },
                error: function (error) {
                    console.log('err');
                    document.getElementById("node").style.display = "none"
                }
            });
            return repData
        }
        //厂区上的跳转链接接口
        function getData7() {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_ZZ_MAPTAB"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_ZZ_MAPTAB.visible === "true") {
                        factory1.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        factory5B.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        //factory2A.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap)
                        factory5A.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        factory2.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        factory8.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        factory9.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                        factory3.s("label", repData.HT_SC_ZZ_MAPTAB.urlMap);
                    }
                },
                error: function (error) {
                    //  console.log('err');
                }
            });
        }
        //返回按钮
        function getData8() {
            const backButton = dataModel.getDataByTag("backButton");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_JD_BUTTON_FH"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_JD_BUTTON_FH.visible === "true") {
                        backButton.a("url", repData.HT_SC_JD_BUTTON_FH.data.url);
                        backButton.s("2d.visible", repData.HT_SC_JD_BUTTON_FH.visible);
                    }
                },
                error: function (error) {
                    //console.log('err');
                }
            });
        }
    </script>
</head>

<body onload='setTimeout(init, 300)'>
    <div id="ct">
        <div id="abc" style="display:none;height: 100%; width:95%">
            <div id="app"
                style="background:url(menu/tree3.png) no-repeat; background-size:100% 100%;position: absolute;z-index:20; width: 11%; height:85%;top:10.5%;overflow: hidden;">
                <span id="total" style="font-size:18px";>兴达公司</span>
                <img class="lin" src="menu/line.png">
                </br></br></br></br>
            </div>
        </div>
        <div id="node"
            style="left:0px;display:block;background-color:rgba(red, green, blue, 0);position:absolute;width: 33px;height: 650px;top: 80px;z-index: 100;">
        </div>
    </div>
</body>

</html>